# connect_to_db

"""Utility functions that are useful in controllers and views
"""

def connect_to_db(config):
  """given a SiteConfig object, connect to the database specified therein."""
  from amplitude.db import Database
  if config.value('Database', 'adaptor') and config.value('Database', 'connection'):
      exec("import %s as dba" % config.value('Database', 'adaptor'))
      db = Database(config.value('Database', 'connection'), dba=dba)
  else:
      db = None
  return db

